package com.smartHome.mapper;

import com.smartHome.pojo.entity.Room;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RoomMapper {
    @Insert("insert into rooms(house_id,room_name,room_type,background_image,create_time,update_time)" +
            "values (#{houseId},#{roomName},#{roomType},#{backgroundImage},now(),now())")
    void add(Room room);

    @Select("SELECT room_id, house_id, room_name, background_image, room_type, create_time, update_time FROM rooms WHERE house_id = #{houseId}")
    List<Room> getByHouseId(Integer houseId);

    @Delete("DELETE from rooms where room_id = #{roomId}")
    void deleteRoomById(Integer roomId);

    @Select("select house_id from rooms where room_id = #{roomId}")
    Integer getHouseId(Integer roomId);
}
